package org.example.taxi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class HiveConfig {

    static {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Hive JDBC Driver not found", e);
        }
    }

    @Value("${hive.jdbc.url}")
    private String jdbcUrl;
    @Value("${hive.jdbc.driver}")
    private String driverClass;
    @Value("${hive.jdbc.username}")
    private String username;
    @Value("${hive.jdbc.password}")
    private String password;

    @Bean
    public JdbcTemplate hiveJdbcTemplate() {
        // 每次调用都会创建新的连接，不推荐高并发使用
        return new JdbcTemplate(new org.springframework.jdbc.datasource.DriverManagerDataSource(this.jdbcUrl, this.username, this.password));
    }
}